package com.cookor.poi.modules.phy.mobile;

import com.cookor.poi.common.utils.JedisUtils;
import com.cookor.poi.common.utils.ResultUtil;
import com.cookor.poi.modules.phy.entity.TWeixinUser;
import com.cookor.poi.modules.phy.service.TWeixinUserService;
import com.cookor.poi.modules.weixin.service.TWeixinConfigService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping({"/api/phy/user"})
@ResponseBody
public class ApiUserController extends ApiBaseController {
  @Autowired
  private TWeixinUserService tWeixinUserService;
  
  @Autowired
  private TWeixinConfigService tWeixinConfigService;
  
  @RequestMapping({"/data"})
  public ResultUtil userData(String openId, HttpServletRequest request) {
    ResultUtil result = getResult();
    try {
      Integer tenantId = getTenantId(request);
      TWeixinUser user = this.tWeixinUserService.getByOpenId(openId);
      result.putParams("user", user);
      JedisUtils.set("test", openId, 300);
      result.putParams("test", JedisUtils.get("test"));
    } catch (Exception e) {
      result.setCode(ResultUtil.ERROR_CODE);
      result.setError(e.getMessage());
      this.logger.error("ApiUserController userData error!", e);
    } 
    return result;
  }
  
  @RequestMapping({"/test"})
  public ResultUtil test(String openId, HttpServletRequest request) {
    ResultUtil result = getResult();
    try {
      System.out.println("1111");
      Thread.sleep(40000L);
      System.out.println("2222");
      return result;
    } catch (Exception e) {
      result.setCode(ResultUtil.ERROR_CODE);
      result.setError(e.getMessage());
      this.logger.error("ApiUserController userData error!", e);
      return result;
    } 
  }
}
